package com.mvp.base

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.annotation.NonNull
import androidx.annotation.Nullable
import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.ToastUtils
import com.mvp.mvpdemo.BuildConfig


/**
 * Created By Mahongyin
 * Date    2020/10/15 16:21
 */
abstract class BaseFragment : Fragment() {
    private val TAG = javaClass.name

    /**
     * fragment 根view
     */
    protected var rootView: View? = null


    @LayoutRes
    protected abstract fun getLayoutId(): Int

    @Nullable
    override fun onCreateView(
        @NonNull inflater: LayoutInflater,
        @Nullable container: ViewGroup?,
        @Nullable savedInstanceState: Bundle?
    ): View? {
        if (rootView == null) {
            rootView = inflater.inflate(getLayoutId(), container, false)
        }
        initCreate()
        return rootView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        initData()
    }


    protected abstract fun initCreate()
    protected abstract fun initData()


    protected fun log(logMessage: String) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, logMessage)
        }
    }


}